package com.yimi.yinhepda.views.load_module;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import com.pda.uce.commom.pickerview.builder.OptionsPickerBuilder;
import com.pda.uce.commom.pickerview.listener.OnOptionsSelectListener;
import com.pda.uce.commom.pickerview.view.OptionsPickerView;
import com.pda.uce.commom.util.MyDialog;
import com.pda.ym.base.BaseTitleActivity;
import com.pda.ym.base.CommonViewHolder;
import com.pda.ym.callbacks.UICallBack;
import com.pda.ym.db.table.CarPlateTable;
import com.pda.ym.entity.bean.CarPlanTaskEntity;
import com.pda.ym.entity.bean.LoadBillTaskEntity;
import com.pda.ym.entity.bean.VehTaskNodeEntity;
import com.pda.ym.entity.response.NoDataResponse;
import com.pda.ym.net.NetRequest;
import com.pda.ym.utils.CarNoSelectDialog;
import com.pda.ym.utils.Constants;
import com.pda.ym.utils.DateHelper;
import com.pda.ym.utils.SoundVibratorManager;
import com.uce.pda.util.ArrayUtils;
import com.yimi.yinhepda.R;
import com.yimi.yinhepda.adapter.LoadUnLoadGroupAdapter;
import com.yimi.yinhepda.adapter.RecycleAdapter.SelectStowageNoAdapter;
import com.yimi.yinhepda.adapter.SelectJoinPeopleAdapter;
import com.yimi.yinhepda.adapter.SpinnerAdapter;
import com.yimi.yinhepda.callbacks.OnClickCallBack;
import com.yimi.yinhepda.db.dao.CarPlateTableDao;
import com.yimi.yinhepda.db.dao.DepartmentTableDao;
import com.yimi.yinhepda.db.dao.LoadUnloadGroupTableDao;
import com.yimi.yinhepda.db.dao.MoveStockTaskCacheTableDao;
import com.yimi.yinhepda.db.dao.OffLineLoadUnloadGroupTableDao;
import com.yimi.yinhepda.db.dao.OffLinePlatformNoTableDao;
import com.yimi.yinhepda.db.dao.UnloadTaskTableDao;
import com.yimi.yinhepda.db.dao.UserInfoTableDao;
import com.yimi.yinhepda.db.table.DepartmentTable;
import com.yimi.yinhepda.db.table.LoadUnLoadGroupTable;
import com.yimi.yinhepda.db.table.MoveStockTaskCacheTable;
import com.yimi.yinhepda.db.table.OffLineLoadUnloadGroupTable;
import com.yimi.yinhepda.db.table.OffLinePlatformNoTable;
import com.yimi.yinhepda.db.table.UnloadTaskTable;
import com.yimi.yinhepda.db.table.UserInfoTable;
import com.yimi.yinhepda.entity.LoadTaskEntity;
import com.yimi.yinhepda.entity.bean.CheckBoxItemEntity;
import com.yimi.yinhepda.entity.bean.CurrentSpaceEntity;
import com.yimi.yinhepda.entity.bean.JoinPeopleEntity;
import com.yimi.yinhepda.entity.bean.LoadUnloadGroupEntity;
import com.yimi.yinhepda.entity.bean.LoaderEntity;
import com.yimi.yinhepda.entity.request.AddUnloaderRequest;
import com.yimi.yinhepda.entity.request.LoadUnloadEmpRequest;
import com.yimi.yinhepda.entity.request.MoveStockLoadTaskNoRequest;
import com.yimi.yinhepda.entity.response.DataStrResponse;
import com.yimi.yinhepda.entity.response.JoinPeopleResponse;
import com.yimi.yinhepda.entity.response.LoadUnLoadGroupResponse;
import com.yimi.yinhepda.entity.response.PlatformNoResponse;
import com.yimi.yinhepda.entity.response.QueryAddUnLoaderDictResponse;
import com.yimi.yinhepda.entity.response.UnBlockingResponse;
import com.yimi.yinhepda.net.QueryPlaceNetRequest;
import com.yimi.yinhepda.utils.Common;
import com.yimi.yinhepda.utils.DialogUtil;
import com.yimi.yinhepda.utils.FilterAdapter;
import com.yimi.yinhepda.views.fenbo_ziti.FenBoZiTiActivity;
import com.yimi.yinhepda.views.kua_yue_spotGoods.KuaYueSpotGoodsActivity;
import com.yimi.yinhepda.views.moveStock_module.load.MoveStockLoadScanActivity;
import com.yimi.yinhepda.views.moveStock_module.unload.MoveStockUnloadScanActivity;
import com.yimi.yinhepda.views.offline.load.OfflLneLoadActivity;
import com.yimi.yinhepda.views.offline.unload.OffLineUnloadActivity;
import com.yimi.yinhepda.views.offline.unload.OffLineUnloadCreateActivity;
import com.yimi.yinhepda.views.unload_module.UnloadScanActivity;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import static com.yimi.yinhepda.utils.Common.SCAN_TYPE_MERGE_UNLOAD;

/**
 * 装卸组界面.
 *
 * @author 000432
 * @date 2018/4/28 0028
 */
public class LoadUnloadGroupActivity extends BaseTitleActivity implements AdapterView.OnItemSelectedListener, View.OnTouchListener, CommonViewHolder.onItemCommonClickListener, CompoundButton.OnCheckedChangeListener {

    /**
     * 月台号.
     */
    private Spinner sp_platformNum;
    /**
     * 装卸组.
     */
    private TextView tv_loadUnloadGroup;
    /**
     * 登陆人工号.
     */
    private EditText et_loginWrokNum;
    /**
     * 登陆人姓名.
     */
    private EditText et_loginName;
    /**
     * 参与人工号.
     */
    private EditText et_joinWorkNum;
    /**
     * 参与人姓名.
     */
    private EditText et_joinName;
    /**
     * 添加参与人.
     */
    private Button btn_addJoinPeople;
    /**
     * 删除参与人.
     */
    private Button btn_deleteJoinPeople;
    /**
     * 参与人列表.
     */
    private ListView lv_joinPeople;
    /**
     * 返回按钮.
     */
    private Button btn_back;
    /**
     * 确定按钮.
     */
    private Button btn_confirm;
    /**
     * 托盘绑定复选框
     */
    private CheckBox cbPalletBind;
    /**
     * 参与人员listview适配器.
     */
    private LoadUnLoadGroupAdapter adapter;
    private List<JoinPeopleEntity> joinPeopleEntityList;
    private List<LoadTaskEntity> loadTaskEntites;
    /**
     * 需要上传卸车配载单合集
     */
    private List<String> uploadUnLoadStowages;
    /**
     * 需要上传卸车配载单
     */
    private String uploadUnLoadStowage;
    /**
     * 上个界面传过来的车牌号、主键、上一站名称.
     */
    private String carNo, task, deptCode;
    /**
     * 卸车当前站（下一站）.
     */
    private List<String> mCurrentDeptCodes;
    /**
     * 扫描类型：1-装车扫描，2=卸车扫描 ,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车,7-单独移库卸车，8-分拨自提,9-跨越点货,10-融合装车，11-融合卸车
     */
    private int scanType;
    private LoadUnLoadGroupTable loadUnLoadGroupTable;
    private LoadUnloadGroupTableDao loadUnloadGroupTableDao;
    private OffLineLoadUnloadGroupTableDao offLineLoadUnloadGroupTableDao;
    private DepartmentTableDao departmentTableDao;
    /**
     * 是否有暂存数据标志.
     */
    private boolean hasTempData = false;
    /**
     * 参与的装卸人员数量.
     */
    private final int ENJOY_PERSON_NUM = 30;
    /**
     * 月台号适配器.
     */
    private SpinnerAdapter platformAdapter;
    /**
     * 月台号数据.
     */
    private List<String> platformList;
    /**
     * 显示月台号按钮.
     */
    private LinearLayout ll_showPlatformNum;
    //月台号输入框
    private AutoCompleteTextView actvPlatformNum;
    private boolean isSpinnerFirst = true;
    /**
     * 装卸车界面跳转过来的类型 ，1-装车，2-卸车,3-离线装车，4-离线卸车
     */
    private int loadType;
    /**
     * 融合：选择下一站
     */
    private LinearLayout llSelectNextDeptMerge;
    private LinearLayout llPlatformNum;
    /**
     * 移至场地
     */
    private LinearLayout llParentMoveSpace;
    private LinearLayout llMoveSpace;
    private TextView tvMoveInName;
    /**
     * 自提窗口
     */
    private LinearLayout llParentZiTi;
    private LinearLayout llZiTi;
    private TextView tvZiTi;
    /**
     * 场地数据集合
     */
    private List<CurrentSpaceEntity> currentSpaceEntityList;
    /**
     * 移至场地实体
     */
    private CurrentSpaceEntity moveInSpaceEntity;
    private TextView tvPlaceTypeName;
    /**
     * 车牌选择按钮
     */
    private Button btnCarPlate;
    private EditText etCarNo;
    /**
     * 临时转换的车牌号
     */
    private String mTempCarNo = "";
    private LinearLayout llParentCarNo;
    private LinearLayout llCarNo;
    /**
     * 月台号
     */
    private LinearLayout llParentPlatformNum;
    /**
     * 下一站
     */
    private LinearLayout llNextDept;
    private TextView tvNextDeptName;
    /**
     * 装卸组、登录人、配载单列表、创建任务类型（快运/快递）
     */
    private LinearLayout llLoadGroup, llLoginPeople, llStowageNo, llCbTaskType;
    /**
     * 复选框：快运、快递
     */
    private CheckBox cbYm, cbUC;
    /**
     * 配载单列表
     */
    private RecyclerView rvStowageNo;
    /**
     * 配载单全选
     */
    private CheckBox cbCheckAll;
    /**
     * 配载上下一站名称
     */
    private TextView tvPreNextDeptName;
    /**
     * 移库倒货任务实体
     */
    private MoveStockTaskCacheTable moveStockCacheEntity;
    private UnBlockingResponse.BarBillTaskEntity mBarBillTaskEntity;

    private int isSelectOptions1;
    private List<DepartmentTable> departmentTableList;
    /**
     * 下一站选择集合
     */
    private List<CheckBoxItemEntity> mCheckNextList;
    /**
     * 卸车配载单任务集合
     */
    private SelectStowageNoAdapter mStowageNoAdapter;
    /**
     * 发车计划任务
     */
    private List<CarPlanTaskEntity> mCarPlaneTasks;
    /**
     * 装卸车任务集合
     */
    private List<LoadBillTaskEntity> mLoadTaskList;
    private List<CheckBoxItemEntity> mSelectNextDepts = new ArrayList<>();
    /**
     * 装卸车参与人
     */
    private String mJoinUserCodes;
    private String mJoinUserName;
    /**
     * 融合装车：创建的配载单集合
     */
    private List<String> mStowageNos;

    @Override
    public String getPageName() {
        return "装卸组界面";
    }

    public LoadUnloadGroupActivity() {
        super(true);
    }

    @Override
    public int setContentViewId() {
        return R.layout.activity_load_unload_group;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

    private void initView() {
        llParentCarNo = findViewById(R.id.ll_parent_carNo);
        llCarNo = findViewById(R.id.ll_carNo);
        btnCarPlate = findViewById(R.id.btn_carPlate);
        btnCarPlate.setOnClickListener(this);
        etCarNo = findViewById(R.id.et_carNo);
        tvPlaceTypeName = findViewById(R.id.tv_placeTypeName);
        tvMoveInName = findViewById(R.id.tv_moveInName);
        llSelectNextDeptMerge = findViewById(R.id.ll_select_next_dept);
        llSelectNextDeptMerge.setOnClickListener(this);
        llPlatformNum = findViewById(R.id.ll_platformNum);
        sp_platformNum = findViewById(R.id.sp_platformNum);
        tv_loadUnloadGroup = findViewById(R.id.tv_loadUnloadGroup);
        et_loginWrokNum = findViewById(R.id.et_loginWrokNum);
        et_loginName = findViewById(R.id.et_loginName);
        et_joinWorkNum = findViewById(R.id.et_joinWorkNum);
        et_joinName = findViewById(R.id.et_joinName);
        btn_addJoinPeople = findViewById(R.id.btn_addJoinPeople);
        btn_deleteJoinPeople = findViewById(R.id.btn_deleteJoinPeople);
        lv_joinPeople = findViewById(R.id.lv_joinPeople);
        btn_back = findViewById(R.id.btn_back);
        btn_confirm = findViewById(R.id.btn_confirm);
        cbPalletBind = findViewById(R.id.cb_palletBind);
        ll_showPlatformNum = findViewById(R.id.ll_showPlatformNum);
        ll_showPlatformNum.setOnClickListener(this);
        ll_showPlatformNum.setOnTouchListener(this);
        actvPlatformNum = findViewById(R.id.actv_platformNum);
        sp_platformNum.setOnItemSelectedListener(this);
        sp_platformNum.setOnTouchListener(this);
        btn_back.setOnClickListener(this);
        btn_confirm.setOnClickListener(this);
        btn_addJoinPeople.setOnClickListener(this);
        btn_deleteJoinPeople.setOnClickListener(this);
        llParentMoveSpace = findViewById(R.id.ll_parent_moveSpace);
        llMoveSpace = findViewById(R.id.ll_moveSpace);
        llMoveSpace.setOnClickListener(this);
        llParentZiTi = findViewById(R.id.ll_parent_zi_ti);
        tvZiTi = findViewById(R.id.tv_zi_ti);
        llZiTi = findViewById(R.id.ll_zi_ti);
        llZiTi.setOnClickListener(this);
        llParentPlatformNum = findViewById(R.id.ll_parent_platformNum);
        llNextDept = findViewById(R.id.ll_nextDept);
        tvNextDeptName = findViewById(R.id.tv_next_dept_name);
        llLoadGroup = findViewById(R.id.ll_loadGroup);
        llLoginPeople = findViewById(R.id.ll_login_people);
        rvStowageNo = findViewById(R.id.rv_stowageNo);
        llStowageNo = findViewById(R.id.ll_stowageNo);
        llCbTaskType = findViewById(R.id.ll_cb_taskType);
        cbYm = findViewById(R.id.cb_ym);
        cbUC = findViewById(R.id.cb_uc);
        cbCheckAll = findViewById(R.id.cb_check_all);
        cbCheckAll.setOnCheckedChangeListener(this);
        tvPreNextDeptName = findViewById(R.id.tv_preNextDeptName);

        et_joinName.addTextChangedListener(new TextWatcher() {
            String str;

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String strs = et_joinName.getText().toString();
                //过滤字符
                str = stringFilter1(strs.toString());
                if (!strs.equals(str)) {
                    et_joinName.setText(str);
                    et_joinName.setSelection(str.length());
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });

        etCarNo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //车牌号英文字母转换成大写
                String carNo = etCarNo.getText().toString().toUpperCase();
                if (!carNo.equalsIgnoreCase(mTempCarNo)) {
                    mTempCarNo = carNo;
                    etCarNo.setText(carNo);
                    etCarNo.setSelection(carNo.length());
                }
            }
        });
    }

    /**
     * 只允许字母和汉字
     *
     * @throws PatternSyntaxException
     */
    public static String stringFilter1(String str) throws PatternSyntaxException {
        String regEx = "[^a-zA-Z\u4E00-\u9FA5]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    private void initData() {

        //设置卸车组标志为未设置,用于分拨卸车暂存和移库装卸车暂存是否跳转至这个界面
        sharedPreferUtil.setBooleanValue(Common.HAS_UNLOAD_GROUP, false);
        //默认隐藏移库至场地布局，当使用移库场地功能时显示 和 车牌号
        llParentMoveSpace.setVisibility(View.GONE);
        llParentCarNo.setVisibility(View.GONE);
        //默认隐藏分拨自提窗口
        llParentZiTi.setVisibility(View.GONE);
        //默认隐藏下一站
        llNextDept.setVisibility(View.GONE);
        //默认隐藏配载单列表
        llStowageNo.setVisibility(View.GONE);
        //默认隐藏创建任务类型
        llCbTaskType.setVisibility(View.GONE);

        mBarBillTaskEntity = (UnBlockingResponse.BarBillTaskEntity) getIntent().getSerializableExtra("barBillTaskEntity");
        //移库卸车任务实体
        moveStockCacheEntity = (MoveStockTaskCacheTable) getIntent().getSerializableExtra("CacheTableEntity");

        //设置车牌
        List<CarPlateTable> carPlateTables = new CarPlateTableDao().getAllData();
        if (carPlateTables != null) {
            if (carPlateTables.size() > 0) {
                btnCarPlate.setText(carPlateTables.get(0).getCarPlate());
            }
        }

        platformList = new ArrayList<>();
        joinPeopleEntityList = new ArrayList<>();
        loadUnloadGroupTableDao = new LoadUnloadGroupTableDao();
        departmentTableDao = new DepartmentTableDao();
        loadUnLoadGroupTable = new LoadUnloadGroupTableDao().getData();

        //扫描类型：扫描类型：1-装车扫描，2=卸车扫描 ,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车,7-单独移库卸车，
        // 8-分拨自提,9-跨越点货,10-融合装车,11-融合卸车
        scanType = getIntent().getIntExtra("scanType", -1);

        if (scanType != Common.SCAN_TYPE_MERGE_LOAD && scanType != SCAN_TYPE_MERGE_UNLOAD) {
            if (loadUnLoadGroupTable != null) {
                //车牌号,用于移库装卸车
                String carNo = loadUnLoadGroupTable.getCarNo();
                btnCarPlate.setText(carNo.substring(0, 1));
                etCarNo.setText(carNo.substring(1, carNo.length()));
                //月台号
                actvPlatformNum.setText(loadUnLoadGroupTable.getPlatform());
                //托盘绑定checkbox
                cbPalletBind.setChecked(loadUnLoadGroupTable.isPalletBindCheck());
                String joinWrokNums = loadUnLoadGroupTable.getWorkNums();
                String joinUserNames = loadUnLoadGroupTable.getUserNames();
                String joinWorkTypes = loadUnLoadGroupTable.getWorkTypes();
                String joinUserCodes = loadUnLoadGroupTable.getUserCodes();
                if (joinWrokNums != null && !joinWrokNums.equals("") && joinUserNames != null) {
                    String[] workNumSplit = joinWrokNums.split(",");
                    String[] userNameSplit = joinUserNames.split(",");
                    String[] workTypeSplit = joinWorkTypes.split(",");
                    String[] userCodesSplit = joinUserCodes.split(",");
                    for (int i = 0; i < workNumSplit.length; i++) {
                        JoinPeopleEntity entity = new JoinPeopleEntity();
                        entity.setWorkNum(workNumSplit[i]);
                        try {
                            entity.setUserName(userNameSplit[i]);
                        } catch (Exception e) {
                            e.printStackTrace();
                            entity.setUserName("");
                        }
                        entity.setJobName(workTypeSplit[i]);
                        entity.setUserCode(userCodesSplit[i]);
                        joinPeopleEntityList.add(entity);
                    }
                }
                hasTempData = true;
            } else {
                //首次没有装卸组数据时，将登陆人添加为装卸人
                hasTempData = false;
                et_joinWorkNum.setText(sharedPreferUtil.getWorkNum());
                addEnjoyPersonMethod();
            }

            loadGroupUIAdapter();
        }

        task = getIntent().getStringExtra("task");
        //设置从卸车界面传递过来的托盘勾选状态
        boolean palletBindCheck = getIntent().getBooleanExtra("palletBindCheck", false);
        cbPalletBind.setChecked(palletBindCheck);

        //装卸车界面跳转过来的类型 ，1-装车，2-卸车,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车，7-单独移库卸车
        loadType = getIntent().getIntExtra("loadType", -1);
        if (scanType == 1 || scanType == 2 || scanType == 5 || scanType == 6 || scanType == 7) {
            /*** 在线装卸组 ***/
            if (scanType == 1) {
                //装车数据
                loadTaskEntites = (List<LoadTaskEntity>) getIntent().getSerializableExtra("LoadTaskEntites");
                cbPalletBind.setVisibility(View.GONE);
            } else if (scanType == 2) {
                //卸车数据
                carNo = getIntent().getStringExtra("carNo");
                deptCode = getIntent().getStringExtra("deptCode");
                //卸车当前站（下一站）
                mCurrentDeptCodes = (List<String>) getIntent().getSerializableExtra("currentDeptCodes");
                cbPalletBind.setVisibility(View.VISIBLE);
                tvPlaceTypeName.setText("卸至场地:");
            } else if (scanType == 5 || scanType == 6 || scanType == 7) {
                //移库装卸车
                tvPlaceTypeName.setText("移至场地:");
                llParentCarNo.setVisibility(View.VISIBLE);
                if (moveStockCacheEntity != null) {
                    String carNo = moveStockCacheEntity.getCarNo();
                    btnCarPlate.setText(carNo.substring(0, 1));
                    etCarNo.setText(carNo.substring(1, carNo.length()));
                    //月台号
                    actvPlatformNum.setText(moveStockCacheEntity.getPlatformNo());
                }
            }

            //在线装车不需要场地功能
            if (scanType != 1) {
                //获取场地信息
                getPlaceInfo();
            }
            //获取当前部门的月台号
            getPlatformNoRequest();
            //获取当前部门的人员信息
            getCurrentDeptEmp();

        } else if (scanType == 3 || scanType == 4) {
            /*** 离线装卸组 ***/
            offLineLoadUnloadGroupTableDao = new OffLineLoadUnloadGroupTableDao();
            //获取离线当前部门的月台号
            getOffLinePlatformNo();
            //获取离线当前部门人员信息
            getOffLineCurrentDeptEmp();
        } else if (scanType == 8) {
            //分拨自提
            //不需要月台号隐藏
            llParentPlatformNum.setVisibility(View.GONE);
            //显示分拨自提窗口
            llParentZiTi.setVisibility(View.VISIBLE);
            //获取当前部门的人员信息
            getCurrentDeptEmp();
            //获取自提网点
            departmentTableList = departmentTableDao.getZiTiDept(sharedPreferUtil.getDeptCode(), "6");
            if (departmentTableList != null && !departmentTableList.isEmpty()) {
                isSelectOptions1 = 0;
                tvZiTi.setText(departmentTableList.get(0).getDeptName());
                tvZiTi.setTag(departmentTableList.get(0).getDeptCode());
            }
        } else if (scanType == Common.SCAN_TYPE_KUAYUE_SPOTGOODS) {
            //跨越点货
            cbPalletBind.setVisibility(View.VISIBLE);
            tvPlaceTypeName.setText("卸至场地:");
            //获取场地信息
            getPlaceInfo();
            //获取当前部门的月台号
            getPlatformNoRequest();
            //获取当前部门的人员信息
            getCurrentDeptEmp();
        } else if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
            //融合装车
            llNextDept.setVisibility(View.VISIBLE);
            llCbTaskType.setVisibility(View.VISIBLE);
            btn_confirm.setText("装车");
            mCarPlaneTasks = (List<CarPlanTaskEntity>) getIntent().getSerializableExtra("carPlaneTasks");

            if (mCarPlaneTasks.size() == 1) {
                //只有一个计划任务时，展示任务类型和下一站，隐藏装车任务列表
                llCbTaskType.setVisibility(View.VISIBLE);
                llNextDept.setVisibility(View.VISIBLE);
                llStowageNo.setVisibility(View.GONE);
            } else {
                //多个计划任务时，展示装车任务列表选择,隐藏任务类型和下一站
                llStowageNo.setVisibility(View.VISIBLE);
                llCbTaskType.setVisibility(View.GONE);
                llNextDept.setVisibility(View.GONE);
                tvPreNextDeptName.setText("下一站");

                mLoadTaskList = new ArrayList<>();
                if (mCarPlaneTasks != null) {
                    for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                        if (!ArrayUtils.isEmpty(planTask.getLoadTasks())) {
                            for (LoadBillTaskEntity unLoadTask : planTask.getLoadTasks()) {
                                if (loadType != 1) {
                                    unLoadTask.setCheck(true);
                                }
                            }
                            mLoadTaskList.addAll(planTask.getLoadTasks());
                        }
                    }
                }
                loadUIStowageAdapter();
            }

            //默认选择 快运 或 者快 递类型
            LoadUtil.createCheckTaskType(mCarPlaneTasks, cbYm, cbUC);

            //设置下一站信息
            getCarPlanTaskNextDept(false);
            //获取当前部门的月台号
            getPlatformNoRequest();
            //获取装卸组设置装卸人信息
            getCurrentDeptEmp();
        } else if (scanType == SCAN_TYPE_MERGE_UNLOAD) {
            //融合卸车
            cbPalletBind.setVisibility(View.VISIBLE);
            llLoadGroup.setVisibility(View.GONE);
            llLoginPeople.setVisibility(View.GONE);
            llStowageNo.setVisibility(View.VISIBLE);
            tvPreNextDeptName.setText("上一站");
            mCarPlaneTasks = (List<CarPlanTaskEntity>) getIntent().getSerializableExtra("carPlaneTasks");

            List<String> stowageNos = new UnloadTaskTableDao().getStowageNo(task);
            mLoadTaskList = new ArrayList<>();
            if (stowageNos != null && !stowageNos.isEmpty()) {
                if (mCarPlaneTasks != null) {
                    for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                        if (planTask.getLoadTasks() != null) {
                            for (LoadBillTaskEntity unLoadTask : planTask.getLoadTasks()) {
                                //有暂存任务的，根据暂存任务选中配载单
                                for (String stowageNo : stowageNos) {
                                    if (stowageNo.equals(unLoadTask.getStowageNo())) {
                                        unLoadTask.setCheck(true);
                                    }
                                }
                            }
                            mLoadTaskList.addAll(planTask.getLoadTasks());
                        }
                    }
                }
            } else {
                //没有暂存任务，默认全部选中
                for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                    if (planTask.getLoadTasks() != null) {
                        for (LoadBillTaskEntity unLoadTask : planTask.getLoadTasks()) {
                            unLoadTask.setCheck(true);
                        }
                        mLoadTaskList.addAll(planTask.getLoadTasks());
                    }
                }
            }
            loadUIStowageAdapter();

            //获取场地信息
            getPlaceInfo();
            //获取当前部门的月台号
            getPlatformNoRequest();
            //获取当前部门的人员信息
            getCurrentDeptEmp();
        }

        if (loadType == 1 || loadType == 2 || loadType == 3 || loadType == 4 || loadType == 5
                || loadType == 6 || loadType == 7 || loadType == Common.SCAN_TYPE_KUAYUE_SPOTGOODS) {
            llPlatformNum.setEnabled(false);
            actvPlatformNum.setEnabled(false);
            ll_showPlatformNum.setEnabled(false);
            llMoveSpace.setEnabled(false);
            tvMoveInName.setEnabled(false);
            llCarNo.setEnabled(false);
        } else {
            llPlatformNum.setEnabled(true);
            actvPlatformNum.setEnabled(true);
            ll_showPlatformNum.setEnabled(true);
            llCarNo.setEnabled(true);
            if (scanType == 6) {
                //移库卸车时禁止选择场地
                llMoveSpace.setEnabled(false);
                tvMoveInName.setEnabled(false);
            } else {
                llMoveSpace.setEnabled(true);
                tvMoveInName.setEnabled(true);
            }
        }
        if (!cbYm.isEnabled() && !cbUC.isEnabled()) {
            llSelectNextDeptMerge.setEnabled(false);
        } else {
            llSelectNextDeptMerge.setEnabled(true);
        }

        et_loginWrokNum.setText(sharedPreferUtil.getWorkNum());
        et_loginName.setText(sharedPreferUtil.getValue(Common.USER_NAME));
    }

    private void loadGroupUIAdapter() {
        if (adapter == null) {
            adapter = new LoadUnLoadGroupAdapter(this, joinPeopleEntityList);
            adapter.setmList(joinPeopleEntityList);
            lv_joinPeople.setAdapter(adapter);
        } else {
            adapter.setmList(joinPeopleEntityList);
            notifyDataSetChanged();
        }
    }

    private void getOffLinePlatformNo() {
        List<OffLinePlatformNoTable> tableList = new OffLinePlatformNoTableDao().getDataByDeptCode(sharedPreferUtil.getDeptCode());
        if (tableList == null || tableList.size() <= 0) {
            platformList.add("请先维护月台号");
            platformAdapter = new SpinnerAdapter<>(LoadUnloadGroupActivity.this, R.layout.simple_spinner_item, platformList);
            sp_platformNum.setAdapter(platformAdapter);
        } else {
            platformList.add("请选择月台号");
            for (OffLinePlatformNoTable entity : tableList) {
                platformList.add(entity.getPlatformNo());
            }
            //spinner适配器
            platformAdapter = new SpinnerAdapter<>(LoadUnloadGroupActivity.this, R.layout.simple_spinner_item, platformList);
            sp_platformNum.setAdapter(platformAdapter);
            //月台号输入框适配器
            FilterAdapter<String> filterAdapter = new FilterAdapter(LoadUnloadGroupActivity.this, android.R.layout.simple_list_item_1, platformList);
            actvPlatformNum.setAdapter(filterAdapter);

            if (loadType == 3 || loadType == 4) {
                //离线装卸车界面跳转过来时，显示已保存的月台号
                if (loadUnLoadGroupTable != null) {
                    for (int i = 0; i < platformList.size(); i++) {
                        if (platformList.get(i).equals(loadUnLoadGroupTable.getPlatform())) {
                            actvPlatformNum.setText(platformList.get(i));
                            break;
                        }
                    }
                }
            }
        }
    }

    /**
     * 获取离线装卸人，根据登录人所在组.
     */
    private void getOffLineCurrentDeptEmp() {
        List<OffLineLoadUnloadGroupTable> tableList = offLineLoadUnloadGroupTableDao.getDataByDeptCode(sharedPreferUtil.getDeptCode());
        if (tableList != null) {
            String teamCode = "";
            for (OffLineLoadUnloadGroupTable entity : tableList) {
                if (entity.getEmpCode() != null) {
                    if (entity.getEmpCode().equals(sharedPreferUtil.getValue(Common.USER_CODE))) {
                        tv_loadUnloadGroup.setText(entity.getTeamName());
                        teamCode = entity.getTeamCode();
                        break;
                    }
                }
            }
            if (!hasTempData) {
                for (OffLineLoadUnloadGroupTable entity : tableList) {
                    if (entity.getEmpCode() == null) {
                        continue;
                    }
                    if (entity.getTeamCode().equals(teamCode)) {
                        //获取相同组人员信息
                        JoinPeopleEntity joinPeopleEntity = new JoinPeopleEntity();
                        if (entity.getEmpName() == null) {
                            joinPeopleEntity.setUserName("");
                        } else {
                            joinPeopleEntity.setUserName(entity.getEmpName());
                        }
                        joinPeopleEntity.setUserCode(entity.getEmpCode());
                        joinPeopleEntity.setWorkNum(entity.getEmpCode().split("@")[0]);
                        joinPeopleEntity.setUserType(entity.getUserType());
                        int userType = entity.getUserType();
                        if (userType == 1 || userType == 2) {
                            //用户类型为1-外部用户，2-内部用户，则设置用户岗位类型为：3-操作工
                            joinPeopleEntity.setJob(Common.OPERATOR_EMP);
                        } else if (userType == 3) {
                            //用户类型为3-外请用户，根据获取的岗位类型设置用户的岗位
                            //岗位类型：3-装卸工,26-试用，27-外请，28-文员
                            String job = entity.getJob();
                            if (job == null || !job.equals(Common.OPERATOR_EMP) && !job.equals(
                                    Common.TRY_USE_EMP) && !job.equals(Common.OUT_PLEASE_EMP)) {
                                //(文员)其他职位类型标志
                                joinPeopleEntity.setJob(Common.CLERK_EMP);
                            } else {
                                joinPeopleEntity.setJob(entity.getJob());
                            }
                        }
                        boolean isExit = false;
                        for (JoinPeopleEntity peopleEntity : joinPeopleEntityList) {
                            if (peopleEntity.getWorkNum().equals(joinPeopleEntity.getWorkNum())) {
                                isExit = true;
                                break;
                            }
                        }
                        if (!isExit) {
                            joinPeopleEntityList.add(joinPeopleEntity);
                        }
                    }
                }
            }
        }
        adapter = new LoadUnLoadGroupAdapter(this, joinPeopleEntityList);
        lv_joinPeople.setAdapter(adapter);
    }

    /**
     * 获取场地信息
     */
    private void getPlaceInfo() {
        if (moveStockCacheEntity != null) {
            //移库装卸车缓存任务传递过来的数据，设置移至场地
            tvMoveInName.setText(moveStockCacheEntity.getMoveInName());
            //保存移至场地数据
            sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_NAME, moveStockCacheEntity.getMoveInName());
            sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_CODE, moveStockCacheEntity.getMoveInCode());
        }

        final QueryPlaceNetRequest placeNetRequest = new QueryPlaceNetRequest().setDeptCode(sharedPreferUtil.getDeptCode());
        //查询该部门是否启用移库倒货功能
        placeNetRequest.queryDataDict(new UICallBack() {
            @Override
            public void onError(String msg) {
                llParentMoveSpace.setVisibility(View.GONE);
            }

            @Override
            public void onSuccess(Object obj) {
                llParentMoveSpace.setVisibility(View.VISIBLE);
                //启用移库倒货功能，则查询场地
                placeNetRequest.querySpaceByDept(new UICallBack() {
                    @Override
                    public void onError(String msg) {

                    }

                    @Override
                    public void onSuccess(Object obj) {
                        //获取到场地数据
                        currentSpaceEntityList = (List<CurrentSpaceEntity>) obj;
                        if (currentSpaceEntityList != null) {
                            //5-移库装车，过滤掉已选当前场地
//                            if (scanType == 5) {
//                                String placeCode = sharedPreferUtil.getValue(Common.PLACE_CODE);
//                                for (CurrentSpaceEntity item : currentSpaceEntityList) {
//                                    if (item.getPlaceCode().equals(placeCode)) {
//                                        currentSpaceEntityList.remove(item);
//                                        break;
//                                    }
//                                }
//                            }
                            if (moveStockCacheEntity != null) {
                                //移库装卸车缓存任务传递过来的数据，设置移至场地
                                tvMoveInName.setText(moveStockCacheEntity.getMoveInName());
                                //保存移至场地数据
                                sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_NAME, moveStockCacheEntity.getMoveInName());
                                sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_CODE, moveStockCacheEntity.getMoveInCode());
                                return;
                            }
                            //设置已选移至场地
                            boolean hasMoveInName = false;
                            String moveInCode = sharedPreferUtil.getValue(Common.MOVE_IN_PLACE_CODE);
                            for (CurrentSpaceEntity item : currentSpaceEntityList) {
                                if (item.getPlaceCode().equals(moveInCode)) {
                                    tvMoveInName.setText(item.getPlaceName());
                                    hasMoveInName = true;
                                }
                            }
                            if (!hasMoveInName && !currentSpaceEntityList.isEmpty()) {
                                String placeName = currentSpaceEntityList.get(0).getPlaceName();
                                tvMoveInName.setText(placeName);
                                //保存移至场地数据
                                sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_NAME, placeName);
                                sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_CODE, currentSpaceEntityList.get(0).getPlaceCode());
                            }
                        } else {
                            showToast("场地数据获取为空！");
                        }
                        loadGroupUIAdapter();
                    }
                });
            }
        });
    }

    /**
     * 获取当前部门的月台号
     */
    private void getPlatformNoRequest() {
        Map<String, String> params = new HashMap<>();
        params.put("deptCode", sharedPreferUtil.getDeptCode());
        //params.put("deptName", "");

        new NetRequest().setMethod(NetRequest.Method.GET)
                .setUrl(Constants.URL_QUERYPLATFORMNO)
                .setParams(params)
                .setResponsClazz(PlatformNoResponse.class)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        showToast("获取月台号失败：" + msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        PlatformNoResponse response = (PlatformNoResponse) obj;
                        if (response.getData() == null || response.getData().size() <= 0) {
                            platformList.add("请先维护月台号");
                        } else {
                            platformList.add("请选择月台号");
                            platformList.addAll(response.getData());
                        }
                        //spinner适配器
                        platformAdapter = new SpinnerAdapter<>(LoadUnloadGroupActivity.this, R.layout.simple_spinner_item, platformList);
                        sp_platformNum.setAdapter(platformAdapter);
                        //月台号输入框适配器
                        FilterAdapter<String> filterAdapter = new FilterAdapter(LoadUnloadGroupActivity.this, android.R.layout.simple_list_item_1, platformList);
                        actvPlatformNum.setAdapter(filterAdapter);

                        if (loadType == 1 || loadType == 2) {
                            //装卸车界面跳转过来时，显示已保存的月台号
                            if (loadUnLoadGroupTable != null) {
                                for (int i = 0; i < platformList.size(); i++) {
                                    if (platformList.get(i).equals(loadUnLoadGroupTable.getPlatform())) {
                                        actvPlatformNum.setText(platformList.get(i));
                                        break;
                                    }
                                }
                            }
                        }
                        loadGroupUIAdapter();
                    }
                });
    }

    @Override
    protected void handleBarCode(String result) {
        if (result == null) {
            SoundVibratorManager.playSound(2);
            showToast("运单号扫描失败");
        } else {
            doScan(result);
        }
    }

    private void doScan(String result) {
        et_joinWorkNum.setText(result);
        //添加参与人
        addEnjoyPersonMethod();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_carPlate:
                //车牌号
                CarNoSelectDialog.showCarPlateDialog(this, new CarNoSelectDialog.CarNoSelectListener() {
                    @Override
                    public void onclick(String carPlate) {
                        btnCarPlate.setText(carPlate);
                    }
                });
                break;
            case R.id.ll_moveSpace:
                //移至场地
                selectPlace();
                break;
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_confirm:
                //扫描类型：1-装车扫描，2=卸车扫描 ,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车,7-单独移库卸车,8-分拨自提,9-跨越点货
                if (scanType == 5 || scanType == 6 || scanType == 7) {
                    String strPlatform = actvPlatformNum.getText().toString().trim();
                    if ("".equals(strPlatform)) {
                        showToast("月台号不能为空！");
                        SoundVibratorManager.playSound(2);
                        return;
                    }

                    String strCarNo = etCarNo.getText().toString().trim();
                    if (strCarNo.equals("")) {
                        showToast("车牌号不能为空！");
                        SoundVibratorManager.playSound(2);
                        return;
                    }
                } else if (scanType == 8) {
                    String ziTiDetpName = tvZiTi.getText().toString();
                    if ("".equals(ziTiDetpName)) {
                        showToast(getString(R.string.please_weihu_ziti));
                        SoundVibratorManager.playSound(2);
                        return;
                    }
                } else if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
                    //融合装车
                    if (tvNextDeptName.getText().toString().equals("")) {
                        showToast("请选择下一站！");
                        SoundVibratorManager.playSound(2);
                        return;
                    }
                }

                //当前装卸人员已经超过额定数量30人，请核实！
                if (joinPeopleEntityList.size() > ENJOY_PERSON_NUM) {
                    MyDialog.showAlertDialog(this, "提示", "当前装卸人员已经超过额定数量" + ENJOY_PERSON_NUM + "人，请核实！", R.color.red, "确定");
                    SoundVibratorManager.playSound(2);
                    return;
                }

                if (joinPeopleEntityList.size() < 1) {
                    showToast("至少有一个参与人！");
                    SoundVibratorManager.playSound(2);
                    return;
                }

                //PDA录入限制:在无我司操作工不参与的情况下，
                // 1.试工人员不能单独操作，只能与操作工一起参与装卸；
                // 2.文员和外请人不能组合进行装卸；
                // 3.外请人或文员可以单独操作；
                // 4.外请人、文员和操作工可以一起操作
                // 3-装卸工，26-试用，27-外请，-1-文员(其他职位的参与人)
                StringBuilder sb = new StringBuilder();
                for (JoinPeopleEntity entity : joinPeopleEntityList) {
                    sb.append(entity.getJob() + ",");
                }
                String jobCode = sb.toString();
                jobCode = jobCode.substring(0, jobCode.length() - 1);
                if (jobCode.contains(Common.TRY_USE_EMP) && !jobCode.contains(Common.OPERATOR_EMP)) {
                    MyDialog.showAlertDialog(this, "提示", "试工人员只能与操作工装卸，请联系分拨管理人员！", R.color.red);
                    return;
                } else if (jobCode.contains(Common.CLERK_EMP)
                        && jobCode.contains(Common.OUT_PLEASE_EMP)
                        && !jobCode.contains(Common.OPERATOR_EMP)
                        && !jobCode
                        .contains(Common.TRY_USE_EMP)) {
                    MyDialog.showAlertDialog(this, "提示", "文员和外请人不能组合进行装卸！请加入分拨装卸人员！", R.color.red);
                    return;
                }

                if (scanType == 2) {
                    //卸车： 调用数据字典配置，判断是否调用添加卸车员接口
                    requestDictValue();
                } else {
                    //继续跳转界面
                    unloadActivityNext();
                }
                break;
            case R.id.btn_addJoinPeople:
                //添加参与人
                addEnjoyPersonMethod();
                break;
            case R.id.btn_deleteJoinPeople:
                //删除参与人
                int count = 0;
                for (JoinPeopleEntity entity : joinPeopleEntityList) {
                    if (entity.isChecked()) {
                        count++;
                    }
                }
                if (count == joinPeopleEntityList.size()) {
                    showToast("至少有一个参与人！");
                    SoundVibratorManager.playSound(2);
                    return;
                } else if (count == 0) {
                    showToast("请选择要删除的参与人！");
                    SoundVibratorManager.playSound(2);
                    return;
                }
                Iterator<JoinPeopleEntity> iterator = joinPeopleEntityList.iterator();
                while (iterator.hasNext()) {
                    JoinPeopleEntity entity = iterator.next();
                    if (entity.isChecked()) {
                        if (joinPeopleEntityList.size() <= 1) {
                            return;
                        }
                        iterator.remove();
                    }
                }
                loadGroupUIAdapter();
                SoundVibratorManager.playSound(1);
                break;
            case R.id.ll_showPlatformNum:
                if (sp_platformNum != null) {
                    sp_platformNum.performClick();
                }
                break;
            case R.id.ll_zi_ti:
                //自提选择窗口
                selectDepterment(departmentTableList);
                break;
            case R.id.ll_select_next_dept:
                //下一站
                if (mCheckNextList == null || mCheckNextList.isEmpty()) {
                    getCarPlanTaskNextDept(true);
                } else {
                    showNextDeptDialog();
                }
                break;
            default:
                break;
        }
    }

    /**
     * 自提选择窗口
     */
    private void selectDepterment(final List<DepartmentTable> deptList) {
        if (deptList == null || deptList.isEmpty()) {
            showToast(getString(R.string.please_weihu_ziti));
            SoundVibratorManager.playSound(2);
            return;
        }
        OptionsPickerView problemOptions = new OptionsPickerBuilder(this,
                new OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        isSelectOptions1 = options1;
                        if (deptList != null && !deptList.isEmpty()) {
                            tvZiTi.setText(deptList.get(options1).getDeptName());
                            tvZiTi.setTag(deptList.get(options1).getDeptCode());
                        }
                    }
                })
                .setTitleText("选择部门")
                //确定按钮文字
                .setSubmitText("确定")
                //取消按钮文字
                .setCancelText("取消")
                //确定按钮文字颜色
                .setSubmitColor(Color.BLACK)
                //取消按钮文字颜色
                .setCancelColor(Color.BLACK)
                //滚轮文字大小
                .setContentTextSize(20)
                //循环与否
                .setCyclic(false, false, false)
                //设置默认选中项
                .setSelectOptions(isSelectOptions1)
                //是否显示为对话框样式
                .isDialog(true)
                .build();
        problemOptions.setPicker(deptList);
        problemOptions.show();
    }

    /**
     * 数据字典：该部门是否添加装卸人字段
     */
    private void requestDictValue() {
        showPgDlg("正在查询配置...");
        Map<String, String> params = new HashMap<>();
        params.put("params", "staff_maintain");
        new NetRequest().setMethod(NetRequest.Method.GET)
                .setUrl(Constants.URL_QUERY_DICT_VALUE)
                .setParams(params)
                .setConnTimeOut(5 * 1000)
                .setResponsClazz(QueryAddUnLoaderDictResponse.class)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        dismissPgDlg();
                        showToast(msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        QueryAddUnLoaderDictResponse response = (QueryAddUnLoaderDictResponse) obj;
                        if (response != null) {
                            if (response.getData() != null) {
                                Map<String, String> maps = response.getData().getMaps();
                                if (maps != null) {
                                    String currDeptCode = sharedPreferUtil.getDeptCode();
                                    for (String value : maps.values()) {
                                        if (value.equals(currDeptCode)) {
                                            uploadUnLoadStowages = new UnloadTaskTableDao().getStowageNo(task);
                                            //调用添加装卸人接口
                                            requestAddUnLoader(uploadUnLoadStowages);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        dismissPgDlg();
                        //没有匹配到需要添加装卸人的部门，继续跳转界面
                        unloadActivityNext();
                    }
                });
    }

    /**
     * 调用添加装卸人接口
     */
    private void requestAddUnLoader(List<String> stowages) {
        if (stowages != null && !stowages.isEmpty()) {
            showPgDlg("正在添加装卸人...");
            AddUnloaderRequest request = new AddUnloaderRequest();
            uploadUnLoadStowage = stowages.get(0);
            request.setStowageNo(uploadUnLoadStowage);
            String userCode = sharedPreferUtil.getValue(Common.USER_CODE);
            List<LoaderEntity> list = new ArrayList<>();
            boolean hasZeRen = false;
            for (JoinPeopleEntity entity : joinPeopleEntityList) {
                LoaderEntity loaderEntity = new LoaderEntity();
                loaderEntity.setEmpName(entity.getUserName());
                loaderEntity.setEmpCode(entity.getUserCode());
                if (entity.getUserCode().equals(userCode)) {
                    loaderEntity.setIsLeader(1);
                    hasZeRen = true;
                } else {
                    loaderEntity.setIsLeader(0);
                }
                loaderEntity.setLatestTime(DateHelper.convertTimeToGmt());
                loaderEntity.setModifierTime(DateHelper.convertTimeToGmt());
                loaderEntity.setRecordVersion(0);
                loaderEntity.setStowageNo(uploadUnLoadStowage);
                list.add(loaderEntity);
            }
            if (!hasZeRen) {
                //如果没有责任人，则默认设置第一个人为责任人
                if (!list.isEmpty()) {
                    list.get(0).setIsLeader(1);
                }
            }
            request.setAddLoaders(list);
            new NetRequest().setMethod(NetRequest.Method.POST_STRING)
                    .setResponsClazz(NoDataResponse.class)
                    .setUrl(Constants.URL_ADD_UNLOADER)
                    .setRequestObject(request)
                    .setConnTimeOut(5 * 1000)
                    .execute(new UICallBack() {
                        @Override
                        public void onError(String msg) {
                            dismissPgDlg();
                            showToast(msg);
                        }

                        @Override
                        public void onSuccess(Object obj) {
                            NoDataResponse response = (NoDataResponse) obj;
                            if (response != null) {
                                if (response.isSuccess()) {
                                    uploadUnLoadStowages.remove(uploadUnLoadStowage);
                                    requestAddUnLoader(uploadUnLoadStowages);
                                } else {
                                    dismissPgDlg();
                                    showToast("添加装卸人接口响应false！");
                                }
                            } else {
                                dismissPgDlg();
                                showToast("添加装卸人接口响应为空！");
                            }
                        }
                    });
        } else {
            dismissPgDlg();
            //继续跳转界面
            unloadActivityNext();
        }
    }

    /**
     * 装卸组界面下一步跳转
     */
    boolean isKuaidiMerge=false;
    private void unloadActivityNext() {
        //参与人工号
        String joinWrokNum = "";
        //参与人姓名
        String joinUserName = "";
        //参与人职位类型
        String joinWorkTypes = "";
        //参与人用户编码
        String joinUserCodes = "";
        for (JoinPeopleEntity entity : joinPeopleEntityList) {
            joinWrokNum += entity.getWorkNum() + ",";
            joinUserName += entity.getUserName() + ",";
            joinWorkTypes += entity.getJobName() + ",";
            joinUserCodes += entity.getUserCode() + ",";
        }
        if (joinWrokNum.length() > 0) {
            joinWrokNum = joinWrokNum.substring(0, joinWrokNum.length() - 1);
        }
        if (joinUserName.length() > 0) {
            joinUserName = joinUserName.substring(0, joinUserName.length() - 1);
        }
        if (joinWorkTypes.length() > 0) {
            joinWorkTypes = joinWorkTypes.substring(0, joinWorkTypes.length() - 1);
        }
        if (joinUserCodes.length() > 0) {
            joinUserCodes = joinUserCodes.substring(0, joinUserCodes.length() - 1);
        }

        //暂存装卸人
        if (loadUnLoadGroupTable == null) {
            loadUnLoadGroupTable = new LoadUnLoadGroupTable();
        }
        loadUnLoadGroupTable.setPlatform(actvPlatformNum.getText().toString().trim());
        loadUnLoadGroupTable.setWorkNums(joinWrokNum);
        loadUnLoadGroupTable.setUserNames(joinUserName);
        loadUnLoadGroupTable.setWorkTypes(joinWorkTypes);
        loadUnLoadGroupTable.setCreateTime(DateHelper.getDateTimeFormate(new Date()));
        loadUnLoadGroupTable.setUserCodes(joinUserCodes);
        loadUnLoadGroupTable.setPalletBindCheck(cbPalletBind.isChecked());
        String strCarNo = btnCarPlate.getText().toString().trim() + etCarNo.getText().toString().trim();
        loadUnLoadGroupTable.setCarNo(strCarNo);
        loadUnloadGroupTableDao.createOrUpdate(loadUnLoadGroupTable);

        sharedPreferUtil.setBooleanValue(Common.HAS_UNLOAD_GROUP, true);

        Intent intent = null;
        Bundle bundle = new Bundle();
        //扫描类型：1-装车扫描，2=卸车扫描 ,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车,7-单独移库卸车,8-分拨自提
        if (scanType == 1) {
            intent = new Intent(this, LoadScanActivity.class);
            bundle.putSerializable("LoadTaskEntites", (Serializable) loadTaskEntites);
        } else if (scanType == 2) {
            intent = new Intent(this, UnloadScanActivity.class);
            bundle.putString("carNo", carNo);
            bundle.putString("task", task);
            bundle.putString("deptCode", deptCode);
            bundle.putSerializable("currentDeptCodes", (Serializable) mCurrentDeptCodes);
            bundle.putSerializable("barBillTaskEntity", mBarBillTaskEntity);
        } else if (scanType == 3) {
            //离线装车
            intent = new Intent(this, OfflLneLoadActivity.class);
            bundle.putString("deptCode", getIntent().getStringExtra("deptCode"));
            bundle.putString("deptName", getIntent().getStringExtra("deptName"));
            bundle.putString("lineType", getIntent().getStringExtra("lineType"));
            bundle.putString("toCompany", getIntent().getStringExtra("toCompany"));
            bundle.putString("offlineTaskNo", getIntent().getStringExtra("offlineTaskNo"));
        } else if (scanType == 4) {
            if (loadType == 4) {
                //跳转至离线卸车扫描界面
                intent = new Intent(this, OffLineUnloadActivity.class);
                intent.putExtra("offlineTaskNo", getIntent().getStringExtra("offlineTaskNo"));
            } else {
                //跳转至离线卸车建立界面
                intent = new Intent(this, OffLineUnloadCreateActivity.class);
            }
        } else if (scanType == 5) {
            if (moveStockCacheEntity != null) {
                //跳转至移库装车界面
                intent = new Intent(LoadUnloadGroupActivity.this, MoveStockLoadScanActivity.class);
                intent.putExtra("CacheTableEntity", moveStockCacheEntity);
            } else {
                //移库装车任务号请求
                doRequestMoveStockLoadTaskNo(1, loadUnLoadGroupTable);
                return;
            }
        } else if (scanType == 6) {
            //跳转至移库卸车界面
            intent = new Intent(this, MoveStockUnloadScanActivity.class);
            intent.putExtra("CacheTableEntity", moveStockCacheEntity);
        } else if (scanType == 7) {
            //创建移库卸车任务号请求
            doRequestMoveStockLoadTaskNo(3, loadUnLoadGroupTable);
            return;
        } else if (scanType == 8) {
            //跳转至分拨自提界面
            intent = new Intent(this, FenBoZiTiActivity.class);
            intent.putExtra("ziTiDeptCode", tvZiTi.getTag().toString());
            intent.putExtra("ziTiDeptName", tvZiTi.getText().toString());
        } else if (scanType == Common.SCAN_TYPE_KUAYUE_SPOTGOODS) {
            //跳转至跨越到达点货界面
            intent = new Intent(this, KuaYueSpotGoodsActivity.class);
            intent.putExtra(Common.KUAYUE_TASK_KEY, getIntent().getSerializableExtra(Common.KUAYUE_TASK_KEY));
        } else if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
            //融合装车

            mJoinUserCodes = joinUserCodes;
            mJoinUserName = joinUserName;

            if (mCarPlaneTasks.size() == 1) {
                //只有一个任务时，通过选择下一站创建任务
                if (!cbYm.isChecked() && !cbUC.isChecked()) {
                    showToast("请至少选择一个任务类型！");
                    SoundVibratorManager.playSound(2);
                    return;
                }
                if (mSelectNextDepts == null || mSelectNextDepts.isEmpty()) {
                    showToast("请至少选择一个下一站！");
                    SoundVibratorManager.playSound(2);
                    return;
                }

                if (mSelectNextDepts.size() > 1) {
                    //提示合并装车
                    LoadUtil.showMergeLoadDialog(this, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            oneCarPlanTaskCreate();
                        }
                    });
                } else {
                    oneCarPlanTaskCreate();
                }

            } else {
                //多个任务时，通过选择配载任务进行装车

                if (!LoadUtil.checkSelectStowageTask(mLoadTaskList, mCarPlaneTasks)) {
                    return;
                }

                 isKuaidiMerge=false;
                int checkCount = 0;
                int kuaidiTaskSelect=0;
                for (LoadBillTaskEntity loadTask : mLoadTaskList) {
                    if (loadTask.isCheck()) {
                        checkCount++;
                        if (!TextUtils.isEmpty(loadTask.getStowageNo())&&!loadTask.getStowageNo().contains("P")){
                            kuaidiTaskSelect++;
                        }
                    }
                }

                if (kuaidiTaskSelect>=2){
                    isKuaidiMerge=true;
                }

                if (checkCount > 1) {
                    //提示合并装车
                    LoadUtil.showMergeLoadDialog(this, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //判断装卸人是否修改后，继续装车任务
                            addLoaderEmpCodes(isKuaidiMerge);
                        }
                    });
                } else if (checkCount == 1) {
                    //判断装卸人是否修改后，继续装车任务
                    addLoaderEmpCodes();
                } else {
                    showToast("未匹配到配载任务！");
                }
            }
            return;

        } else if (scanType == SCAN_TYPE_MERGE_UNLOAD) {
            //融合卸车

            if (!LoadUtil.checkSelectStowageTaskForUnload(mLoadTaskList, mCarPlaneTasks)) {
                return;
            }

            mJoinUserCodes = joinUserCodes;
            mJoinUserName = joinUserName;

            //调用添加装卸人接口，然后跳转至卸车扫描界面
            addLoaderEmpCodes();

            return;
        }
        bundle.putString("joinWrokNum", joinUserCodes);
        bundle.putString("joinUserName", joinUserName);
        if (intent != null) {
            intent.putExtras(bundle);
            //清空已存在的Activity，重新创建Activity
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            if (scanType != 8) {
                finish();
            }
        } else {
            showToast("intent为空！");
        }
    }

    /**
     * 一个计划装车任务创建装车
     */
    private void oneCarPlanTaskCreate() {
        boolean scanSwitch = sharedPreferUtil.getBooleanValue(Constants.MERGE_LOAD_SCAN_TASK_SWITCH);
        if (scanSwitch) {
            //融合装车扫描创建任务开启
            //设置已选中的装车任务状态
            for (CheckBoxItemEntity selectedNextDept : mSelectNextDepts) {
                for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                    if (planTask.getLoadTasks() != null) {
                        for (LoadBillTaskEntity loadTask : planTask.getLoadTasks()) {
                            if (selectedNextDept.getCode().equals(loadTask.getDestDeptCode())) {
                                loadTask.setCheck(true);
                            }
                        }
                    }
                    for (VehTaskNodeEntity node : planTask.getNodes()) {
                        if (selectedNextDept.getCode().equals(node.getTaskNodeCode())) {
                            node.setSelected(true);
                        }
                    }
                }
            }
            gotoNextScanActivity();
        } else {
            boolean hasBeTask = false;
            for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                if (planTask.getBeTask() == 1) {
                    //车线任务
                    hasBeTask = true;
                } else {
                    if (planTask.getLoadTasks() != null) {
                        for (LoadBillTaskEntity loadTask : planTask.getLoadTasks()) {
                            loadTask.setCheck(true);
                        }
                    }
                }
            }
            if (hasBeTask) {
                //车线任务调用创建接口
                createLoadTask();
            } else {
                //非车线任务调修改装卸人接口
                addLoaderEmpCodes();
            }
        }
    }

    /**
     * 继续跳转至装卸车扫描界面
     */
    private void gotoNextScanActivity() {
        gotoNextScanActivity(false);
    }

    private void gotoNextScanActivity(boolean isKuaidiMergeToActivity) {
        Intent intent;
        Bundle bundle = new Bundle();
        String task = Constants.getUUID();
        if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
            //融合装车
            if (new UnloadTaskTableDao().noExitInsert(UnloadTaskTable.parseUnloadTable2(task, mCarPlaneTasks, 1), 1) >= 0) {
                intent = new Intent(LoadUnloadGroupActivity.this, LoadScanActivity.class);
                if (isKuaidiMergeToActivity){
                    intent.putExtra("isKuaidiMerge",1);
                }
            } else {
                showToast("保存装车任务失败！");
                return;
            }
        } else {
            //融合卸车
            UnloadTaskTableDao unloadTaskTableDao = new UnloadTaskTableDao();
            //本地任务表中删除未选择的任务
            for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                if (planTask.getLoadTasks() != null) {
                    for (LoadBillTaskEntity loadTask : planTask.getLoadTasks()) {
                        if (!loadTask.isCheck()) {
                            unloadTaskTableDao.deleteByStowage(sharedPreferUtil.getValue(Common.USER_CODE), loadTask.getStowageNo(), 2);
                        }
                    }
                }
            }

            int result = unloadTaskTableDao.noExitInsert(UnloadTaskTable.parseUnloadTable2(task, mCarPlaneTasks, 2), 2);
            if (result >= 0) {
                intent = new Intent(LoadUnloadGroupActivity.this, UnloadScanActivity.class);
            } else {
                showToast("保存卸车任务失败！");
                return;
            }
        }
        bundle.putString("joinWrokNum", mJoinUserCodes);
        bundle.putString("joinUserName", mJoinUserName);
        bundle.putSerializable("carPlaneTasks", (Serializable) mCarPlaneTasks);
        bundle.putString("task", task);
        bundle.putSerializable("joinPeopleList", (Serializable) joinPeopleEntityList);
        bundle.putSerializable("selectedNextDepts", (Serializable) mSelectNextDepts);
        intent.putExtras(bundle);
        //清空已存在的Activity，重新创建Activity
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }

    /**
     * 融合：创建装车任务
     */
    private void createLoadTask() {

        //选择创建任务类型
        int createType;
        if (cbYm.isChecked() && cbUC.isChecked()) {
            createType = 0;
        } else if (cbYm.isChecked()) {
            //快运
            createType = 1;
        } else {
            //快递
            createType = 2;
        }

        showPgDlg("创建中...");
        LoadUtil.createLoadTask(mSelectNextDepts, mCarPlaneTasks, joinPeopleEntityList, createType, new UICallBack() {
            @Override
            public void onError(String msg) {
                dismissPgDlg();
                showToast(msg);
                SoundVibratorManager.playSound(2);
            }

            @Override
            public void onSuccess(Object obj) {
                dismissPgDlg();
                if (obj instanceof Boolean) {
                    //没有修改下一站,判断有修改装卸人就调接口修改，没有则直接跳转至扫描界面
                    addLoaderEmpCodes();
                }
            }
        });
    }

    /**
     * 修改装卸车参与人接口
     */
    private void addLoaderEmpCodes() {
        addLoaderEmpCodes(false);
    }


    private void addLoaderEmpCodes(final boolean isKuaidiMergeParams) {
        //调用添加装卸人接口，然后跳转至卸车扫描界面
        showPgDlg("添加参与人中...");
        LoadUtil.addLoaderEmpCodes(joinPeopleEntityList, mCarPlaneTasks, scanType, actvPlatformNum.getText().toString(),
                new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        dismissPgDlg();
                        showToast(msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        dismissPgDlg();

                        //设置装卸任务参与人
                        String joinPeoples = "";
                        for (JoinPeopleEntity joinPeople : joinPeopleEntityList) {
                            joinPeoples += joinPeople.getUserCode() + ",";
                        }
                        joinPeoples = joinPeoples.substring(0, joinPeoples.length() - 1);
                        for (CarPlanTaskEntity carPlanTask : mCarPlaneTasks) {
                            if (carPlanTask.getLoadTasks() != null) {
                                for (LoadBillTaskEntity loadTask : carPlanTask.getLoadTasks()) {
                                    if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
                                        //装车任务
                                        loadTask.setLoadEmpCodes(joinPeoples);
                                    } else if (scanType == SCAN_TYPE_MERGE_UNLOAD) {
                                        //卸车任务
                                        loadTask.setUnloadEmpCodes(joinPeoples);
                                    }
                                }
                            }
                        }

                        //跳转至扫描界面
                        gotoNextScanActivity(isKuaidiMergeParams);
                    }
                });
    }

    /**
     * 移库装卸车任务号请求
     *
     * @param transType  装车中 1  装车已提交 2 卸车中3 卸车已完成4
     * @param groupTable 装卸组数据
     */
    private void doRequestMoveStockLoadTaskNo(final int transType, final LoadUnLoadGroupTable groupTable) {
        MoveStockLoadTaskNoRequest request = new MoveStockLoadTaskNoRequest();
        request.setDeptCode(sharedPreferUtil.getDeptCode());
        request.setDeptName(sharedPreferUtil.getValue(Common.DEPT_NAME));
        request.setCompCode(sharedPreferUtil.getCompanyCode());
        request.setCompName(sharedPreferUtil.getCompanyName());
        //移库状态 1-场内出库中，2-移库中，3-场内入库中，4-入场地完成(装车中 1  装车已提交 2 卸车中3 卸车已完成4)
        request.setTransType(transType);
        //车牌号码
        final String strCarNo = btnCarPlate.getText().toString().trim() + etCarNo.getText().toString().trim();
        request.setCarNo(strCarNo);
        String userCode = sharedPreferUtil.getValue(Common.USER_CODE);
        String empName = sharedPreferUtil.getEmpName();
        String platformNo = actvPlatformNum.getText().toString().trim();
        request.setLoadAreaCode(sharedPreferUtil.getValue(Common.PLACE_CODE));
        request.setLoadAreaName(sharedPreferUtil.getValue(Common.PLACE_NAME));
        request.setLoadEmpNo(userCode);
        request.setLoadEmpName(empName);
        request.setLoadPlantformNo(platformNo);
        request.setUnloadAreaCode(sharedPreferUtil.getValue(Common.MOVE_IN_PLACE_CODE));
        request.setUnloadAreaName(sharedPreferUtil.getValue(Common.MOVE_IN_PLACE_NAME));
        //卸车创建（东北）
        request.setUnloadEmpNo(userCode);
        request.setUnloadEmpName(empName);
        request.setUnloadPlantformNo(platformNo);

        showPgDlg("数据提交中...");
        new NetRequest().setMethod(NetRequest.Method.POST_STRING)
                .setResponsClazz(DataStrResponse.class)
                .setUrl(Constants.URL_GET_MOVE_STOCK_TASK_NO)
                .setRequestObject(request)
                .setConnTimeOut(5 * 1000)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        dismissPgDlg();
                        showToast(msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        dismissPgDlg();
                        DataStrResponse response = (DataStrResponse) obj;
                        //获取移库装车创建任务号
                        String taskNo = response.getData();
                        //暂存移库装车任务
                        MoveStockTaskCacheTable cacheTable = new MoveStockTaskCacheTable();
                        cacheTable.setDeptCode(sharedPreferUtil.getDeptCode());
                        cacheTable.setOperCode(sharedPreferUtil.getValue(Common.USER_CODE));
                        cacheTable.setTaskNo(taskNo);
                        cacheTable.setMoveOutCode(sharedPreferUtil.getValue(Common.PLACE_CODE));
                        cacheTable.setMoveOutName(sharedPreferUtil.getValue(Common.PLACE_NAME));
                        cacheTable.setMoveInCode(sharedPreferUtil.getValue(Common.MOVE_IN_PLACE_CODE));
                        cacheTable.setMoveInName(sharedPreferUtil.getValue(Common.MOVE_IN_PLACE_NAME));
                        cacheTable.setCarNo(strCarNo);
                        cacheTable.setPiaoNum(0);
                        if (transType == 1) {
                            //装车类型
                            cacheTable.setOperType(1);
                        } else if (transType == 3) {
                            //卸车类型
                            cacheTable.setOperType(2);
                        }
                        cacheTable.setPlatformNo(actvPlatformNum.getText().toString().trim());
                        try {
                            new MoveStockTaskCacheTableDao().insert(cacheTable);
                        } catch (SQLException e) {
                            e.printStackTrace();
                            showToast("暂存移库装车任务失败！");
                            return;
                        }

                        Intent intent = null;
                        if (transType == 1) {
                            //跳转至移库装车界面
                            intent = new Intent(LoadUnloadGroupActivity.this, MoveStockLoadScanActivity.class);
                        } else if (transType == 3) {
                            //跳转至移库卸车界面
                            intent = new Intent(LoadUnloadGroupActivity.this, MoveStockUnloadScanActivity.class);
                        }
                        intent.putExtra("joinWrokNum", groupTable.getUserCodes());
                        intent.putExtra("joinUserName", groupTable.getUserNames());
                        intent.putExtra("CacheTableEntity", cacheTable);
                        //清空已存在的Activity，重新创建Activity
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                        finish();
                    }
                });
    }

    /**
     * 选择场地
     */
    private void selectPlace() {
        if (currentSpaceEntityList == null || currentSpaceEntityList.isEmpty()) {
            showToast("未查询到场地！");
            return;
        }

        final QueryPlaceNetRequest placeNetRequest = new QueryPlaceNetRequest();
        placeNetRequest.setDeptCode(sharedPreferUtil.getDeptCode());
        placeNetRequest.setTitle("请选择移至场地");
        placeNetRequest.showSelectSpaceDialog(LoadUnloadGroupActivity.this, currentSpaceEntityList, new OnClickCallBack() {
            @Override
            public void onCancle() {
            }

            @Override
            public void onSure(Object obj, Object dialog) {
                moveInSpaceEntity = (CurrentSpaceEntity) obj;
                if (moveInSpaceEntity != null && moveInSpaceEntity.isCheck()) {
                    Dialog mDilaog = (Dialog) dialog;
                    mDilaog.dismiss();
                    tvMoveInName.setText(moveInSpaceEntity.getPlaceName());
                    //保存移至场地数据
                    sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_NAME, moveInSpaceEntity.getPlaceName());
                    sharedPreferUtil.setValue(Common.MOVE_IN_PLACE_CODE, moveInSpaceEntity.getPlaceCode());
                } else {
                    showToast("请选择移至场地！");
                }
            }
        });
    }

    /**
     * 添加参与装卸人功能
     */
    private void addEnjoyPersonMethod() {
        final String joinWorkNum = et_joinWorkNum.getText().toString().trim();
        final String joinName = et_joinName.getText().toString().trim();
        if (joinWorkNum.equals("") && joinName.equals("")) {
            showToast("请输入工号或姓名！");
            SoundVibratorManager.playSound(2);
            return;
        }
        if (joinName.equals("") && joinWorkNum.length() < 6) {
            //工号小于六位数则提示
            showToast("工号不能小于六位数！");
            SoundVibratorManager.playSound(2);
            return;
        }
        //当前装卸人员已经超过额定数量30人，请核实！
        if (joinPeopleEntityList.size() >= ENJOY_PERSON_NUM) {
            MyDialog.showAlertDialog(this, "提示", "当前装卸人员已经超过额定数量" + ENJOY_PERSON_NUM + "人，请核实！", R.color.red, "确定");
            SoundVibratorManager.playSound(2);
            return;
        }
        for (JoinPeopleEntity entity : joinPeopleEntityList) {
            if (entity.getWorkNum().equals(joinWorkNum)) {
                showToast(getString(R.string.hasJoinedPeople));
                SoundVibratorManager.playSound(2);
                return;
            }
        }
        //扫描类型：1-装车扫描，2=卸车扫描 ,3-离线装车，4-离线卸车,5-移库装车，6-移库卸车,7-单独移库卸车，8-分拨自提
        if (scanType == 3 || scanType == 4) {
            /***离线员工添加***/
            addoffLineUser(joinWorkNum, joinName);
        } else {
            /***在线员工查询并添加***/
            queryUserRequest(joinWorkNum, joinName);
        }
    }

    /**
     * 添加离线员工
     */
    private void addoffLineUser(String joinWorkNum, String joinName) {
        boolean hasUser = true;
        int userType = 0;
        String job = null;
        UserInfoTableDao userInfoTableDao = new UserInfoTableDao();
        JoinPeopleEntity joinPeopleEntity = new JoinPeopleEntity();
        List<UserInfoTable> userInfoTableList = userInfoTableDao.getDataByUserNameAndWorkNum(joinWorkNum, joinName);
        if (userInfoTableList == null || userInfoTableList.isEmpty()) {
            hasUser = false;
        } else if (userInfoTableList.size() == 1) {
            UserInfoTable userInfoTable = userInfoTableList.get(0);
            joinPeopleEntity.setUserCode(userInfoTable.getUserCode());
            joinWorkNum = userInfoTable.getWorkNum();
            joinName = userInfoTable.getUserName();
            userType = userInfoTable.getUserType();
            job = userInfoTable.getJob();
        } else {
            //多个装卸人弹出框选择
            getSelectJoinPeople(userInfoTableList);
            return;
        }

        //1-内部用户，2-外部用户，3-外请用户.
        if (userType == 1 || userType == 2) {
            joinPeopleEntity.setJob(Common.OPERATOR_EMP);
        } else {
            //用户类型为3-外请用户，根据获取的岗位类型设置用户的岗位
            //岗位类型：3-装卸工,26-试用，27-外请，28-文员
            if (job == null || !job.equals(Common.OPERATOR_EMP) && !job.equals(
                    Common.TRY_USE_EMP) && !job.equals(Common.OUT_PLEASE_EMP)) {
                //(文员)其他职位类型标志
                joinPeopleEntity.setJob(Common.CLERK_EMP);
            } else {
                joinPeopleEntity.setJob(job);
            }
        }
        joinPeopleEntity.setWorkNum(joinWorkNum);
        joinPeopleEntity.setUserName(joinName);
        for (JoinPeopleEntity entity : joinPeopleEntityList) {
            if (entity.getWorkNum().equals(joinWorkNum)) {
                showToast(getString(R.string.hasJoinedPeople));
                SoundVibratorManager.playSound(2);
                return;
            }
        }
        if (!hasUser) {
            showDialogOfflineAddUser(joinPeopleEntity);
        } else {
            joinPeopleEntityList.add(joinPeopleEntity);
            loadGroupUIAdapter();
            SoundVibratorManager.playSound(1);
        }
    }

    /**
     * 选择参与人
     */
    private void getSelectJoinPeople(List<UserInfoTable> userInfoTableList) {
        final List<JoinPeopleEntity> entityList = new ArrayList<>();
        for (UserInfoTable entity : userInfoTableList) {
            JoinPeopleEntity joinPeopleEntity = new JoinPeopleEntity();
            joinPeopleEntity.setUserName(entity.getUserName());
            joinPeopleEntity.setUserType(entity.getUserType());
            joinPeopleEntity.setWorkNum(entity.getWorkNum());
            joinPeopleEntity.setJob(entity.getJob());
            joinPeopleEntity.setUserCode(entity.getUserCode());
            entityList.add(joinPeopleEntity);
        }
        //多个参与人时，弹出对话框选择参与人
        LinearLayout layout =
                (LinearLayout) LayoutInflater.from(LoadUnloadGroupActivity.this).inflate(R.layout.alert_dialog_select_join_people, null);
        final Dialog dialog = new Dialog(LoadUnloadGroupActivity.this, R.style.AsyncTaskDialog);
        ListView lv_slectPeople = (ListView) layout.findViewById(R.id.lv_selectPeople);
        dialog.addContentView(layout,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().getDecorView().setPadding(10, 0, 10, 0);
        dialog.show();
        //选择参与人适配器
        SelectJoinPeopleAdapter selectJoinPeopleAdapter = new SelectJoinPeopleAdapter(LoadUnloadGroupActivity.this, entityList);
        lv_slectPeople.setAdapter(selectJoinPeopleAdapter);
        lv_slectPeople.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                                    long id) {
                JoinPeopleEntity joinPeopleEntity = entityList.get(position);
                for (JoinPeopleEntity entity : joinPeopleEntityList) {
                    if (entity.getWorkNum().equals(joinPeopleEntity.getWorkNum())) {
                        showToast(getString(R.string.hasJoinedPeople));
                        return;
                    }
                }
                int userType = joinPeopleEntity.getUserType();
                if (userType == 1 || userType == 2) {
                    joinPeopleEntity.setJob(Common.OPERATOR_EMP);
                } else {
                    String job = joinPeopleEntity.getJob();
                    if (job == null || job.equals("")) {
                        joinPeopleEntity.setJob(Common.CLERK_EMP);
                    } else if (!job.equals(Common.OPERATOR_EMP) && !job.equals(
                            Common.OUT_PLEASE_EMP) && !job.equals(Common.TRY_USE_EMP)) {
                        joinPeopleEntity.setJob(Common.CLERK_EMP);
                    }
                }
                joinPeopleEntityList.add(joinPeopleEntity);
                dialog.dismiss();
                adapter.setmList(joinPeopleEntityList);
                loadGroupUIAdapter();
                SoundVibratorManager.playSound(1);
            }
        });
    }

    /**
     * 离线人员添加时未查询到时提示
     */
    private void showDialogOfflineAddUser(final JoinPeopleEntity joinPeopleEntity) {
        final MyDialog dialog = new MyDialog(this);
        dialog.setIcon(R.drawable.alert);
        dialog.setDialogType(MyDialog.DialogType.ALERT_DIALOG);
        dialog.setTitle("提示");
        dialog.setMessage("当前添加的人员信息不存在，是否继续添加？");
        dialog.setPositiveClickListener("是", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                joinPeopleEntityList.add(joinPeopleEntity);
                adapter.setmList(joinPeopleEntityList);
                loadGroupUIAdapter();
                SoundVibratorManager.playSound(1);
            }
        });
        dialog.setNegativeClickListener(R.drawable.btn_login_selector, "否", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 在线员工查询并添加
     *
     * @param joinWorkNum 工号
     * @param joinName    姓名
     */
    private void queryUserRequest(String joinWorkNum, String joinName) {
        showPgDlg("正在查询...");
        //通过接口获取参与人信息
        Map param = new HashMap();
        param.put("siteCode", sharedPreferUtil.getDeptCode());
        if (!joinWorkNum.equals("")) {
            //优先查询工号
            param.put("keyword", joinWorkNum);
        } else if (!joinName.equals("")) {
            param.put("keyword", joinName);
        }
        new NetRequest().setMethod(NetRequest.Method.GET)
                .setUrl(Constants.URL_QUERY_JOIN_PEOPLE)
                .setParams(param)
                .setResponsClazz(JoinPeopleResponse.class)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        dismissPgDlg();
                        showToast(msg);
                        SoundVibratorManager.playSound(2);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        dismissPgDlg();
                        if (obj instanceof JoinPeopleResponse) {
                            JoinPeopleResponse response = (JoinPeopleResponse) obj;
                            JoinPeopleResponse.Data data = response.getData();
                            int totalRecord = data.getTotalRecord();
                            if (totalRecord <= 0) {
                                showToast("未查询到该员工！");
                                SoundVibratorManager.playSound(2);
                                return;
                            }
                            List<JoinPeopleEntity> records = data.getRecords();
                            if (records != null && records.size() > 0) {
                                if (records.size() == 1) {
                                    JoinPeopleEntity joinPeopleEntity = records.get(0);
                                    String userCode = joinPeopleEntity.getUserCode();
                                    if (userCode == null || userCode.equals("")) {
                                        showToast("此参与人用户编码为空，不予添加！");
                                        SoundVibratorManager.playSound(2);
                                        return;
                                    }
                                    for (JoinPeopleEntity entity : joinPeopleEntityList) {
                                        if (joinPeopleEntity.getWorkNum().equals(entity.getWorkNum())) {
                                            showToast(getString(R.string.hasJoinedPeople));
                                            SoundVibratorManager.playSound(2);
                                            return;
                                        }
                                    }
                                    //只查询到一个参与人时直接添加到list中
                                    joinPeopleEntityList.add(joinPeopleEntity);
                                    adapter.setmList(joinPeopleEntityList);
                                    loadGroupUIAdapter();
                                    SoundVibratorManager.playSound(1);
                                } else if (records.size() > 1) {
                                    final List<JoinPeopleEntity> entityList = new ArrayList<>();
                                    for (JoinPeopleEntity entity : records) {
                                        entityList.add(entity);
                                    }
                                    //多个参与人时，弹出对话框选择参与人
                                    LinearLayout layout =
                                            (LinearLayout) LayoutInflater.from(LoadUnloadGroupActivity.this).inflate(R.layout.alert_dialog_select_join_people, null);
                                    final Dialog dialog = new Dialog(LoadUnloadGroupActivity.this, R.style.AsyncTaskDialog);
                                    ListView lv_slectPeople = layout.findViewById(R.id.lv_selectPeople);
                                    dialog.addContentView(layout,
                                            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                                    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
                                    dialog.getWindow().getDecorView().setPadding(10, 0, 10, 0);
                                    dialog.show();
                                    //选择参与人适配器
                                    SelectJoinPeopleAdapter selectJoinPeopleAdapter = new SelectJoinPeopleAdapter(LoadUnloadGroupActivity.this, entityList);
                                    lv_slectPeople.setAdapter(selectJoinPeopleAdapter);
                                    lv_slectPeople.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                        @Override
                                        public void onItemClick(AdapterView<?> parent, View view, int position,
                                                                long id) {
                                            JoinPeopleEntity joinPeopleEntity = entityList.get(position);
                                            for (JoinPeopleEntity entity : joinPeopleEntityList) {
                                                if (entity.getWorkNum().equals(joinPeopleEntity.getWorkNum())) {
                                                    showToast(getString(R.string.hasJoinedPeople));
                                                    return;
                                                }
                                            }
                                            String userCode = joinPeopleEntity.getUserCode();
                                            if (userCode == null || userCode.equals("")) {
                                                showToast("此参与人用户编码为空，不予添加！");
                                                SoundVibratorManager.playSound(2);
                                                return;
                                            }
                                            joinPeopleEntityList.add(joinPeopleEntity);
                                            dialog.dismiss();
                                            adapter.setmList(joinPeopleEntityList);
                                            loadGroupUIAdapter();
                                            SoundVibratorManager.playSound(1);
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
    }

    /**
     * 获取当前网点装卸组员工信息
     */
    private void getCurrentDeptEmp() {
        showPgDlg("查询中...");
        LoadUnloadEmpRequest empRequest = new LoadUnloadEmpRequest();
        empRequest.setDeptCode(sharedPreferUtil.getDeptCode());
        new NetRequest().setMethod(NetRequest.Method.POST_STRING)
                .setUrl(Constants.URL_QUERY_LOAD_TEAM)
                .setRequestObject(empRequest)
                .setResponsClazz(LoadUnLoadGroupResponse.class)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        dismissPgDlg();
                        showToast(msg);
                        joinPeopleEntityList.clear();
                        loadGroupUIAdapter();
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        dismissPgDlg();
                        if (obj instanceof LoadUnLoadGroupResponse) {
                            LoadUnLoadGroupResponse response = (LoadUnLoadGroupResponse) obj;
                            List<LoadUnloadGroupEntity> groupEntityList = response.getData().getEmps();
                            UserInfoTableDao userInfoDao = new UserInfoTableDao();
                            if (scanType == Common.SCAN_TYPE_MERGE_LOAD || scanType == SCAN_TYPE_MERGE_UNLOAD) {
                                //融合装车/卸车
                                boolean needJoinPeople = false;
                                if (mCarPlaneTasks != null) {
                                    for (CarPlanTaskEntity planTask : mCarPlaneTasks) {
                                        if (scanType == Common.SCAN_TYPE_MERGE_LOAD) {
                                            //融合装车
                                            if (planTask.getLoadTasks() == null) {
                                                needJoinPeople = true;
                                            }
                                            if (planTask.getLoadTasks() != null) {
                                                for (LoadBillTaskEntity loadTask : planTask.getLoadTasks()) {
                                                    if (loadTask.getLoadEmpCodes() != null) {
                                                        String[] empCodes = loadTask.getLoadEmpCodes().split(",");
                                                        if (empCodes.length > 0) {
                                                            if (groupEntityList != null) {
                                                                for (String empCode : empCodes) {
                                                                    boolean hasEmpCode = false;
                                                                    for (LoadUnloadGroupEntity entity : groupEntityList) {
                                                                        if (entity.getEmpCode() != null) {
                                                                            if (entity.getEmpCode().equals(empCode)) {
                                                                                hasEmpCode = true;
                                                                                //获取相同装卸人信息
                                                                                setjoinPeopleList(entity);
                                                                            }
                                                                        }
                                                                    }
                                                                    if (!hasEmpCode) {
                                                                        empCode = empCode.split("@")[0];
                                                                        addEmpCode(empCode);
                                                                    }
                                                                }
                                                            } else {
                                                                //装卸组为空，通过 装车参与人 查询本地部门用户信息
                                                                for (String empCode : empCodes) {
                                                                    UserInfoTable userInfoTable = userInfoDao.getDataByWorkNum(empCode.split("@")[0]);
                                                                    if (userInfoTable != null) {
                                                                        LoadUnloadGroupEntity entity = new LoadUnloadGroupEntity();
                                                                        entity.setEmpCode(empCode);
                                                                        entity.setEmpName(userInfoTable.getUserName());
                                                                        setjoinPeopleList(entity);
                                                                    } else {
                                                                        empCode = empCode.split("@")[0];
                                                                        addEmpCode(empCode);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        needJoinPeople = true;
                                                    }
                                                }
                                            }
                                        } else {
                                            //融合卸车
                                            if (planTask.getLoadTasks() == null) {
                                                needJoinPeople = true;
                                            }
                                            if (planTask.getLoadTasks() != null) {
                                                for (LoadBillTaskEntity loadTask : planTask.getLoadTasks()) {
                                                    if (loadTask.getUnloadEmpCodes() != null) {
                                                        String[] empCodes = loadTask.getUnloadEmpCodes().split(",");
                                                        if (empCodes.length > 0) {
                                                            if (groupEntityList != null) {
                                                                for (String empCode : empCodes) {
                                                                    boolean hasEmpCode = false;
                                                                    for (LoadUnloadGroupEntity entity : groupEntityList) {
                                                                        if (entity.getEmpCode() != null) {
                                                                            if (entity.getEmpCode().equals(empCode)) {
                                                                                hasEmpCode = true;
                                                                                //获取相同装卸人信息
                                                                                setjoinPeopleList(entity);
                                                                            }
                                                                        }
                                                                    }
                                                                    if (!hasEmpCode) {
                                                                        empCode = empCode.split("@")[0];
                                                                        addEmpCode(empCode);
                                                                    }
                                                                }
                                                            } else {
                                                                //装卸组为空，通过 装车参与人 查询本地部门用户信息
                                                                for (String empCode : empCodes) {
                                                                    UserInfoTable userInfoTable = userInfoDao.getDataByWorkNum(empCode.split("@")[0]);
                                                                    if (userInfoTable != null) {
                                                                        LoadUnloadGroupEntity entity = new LoadUnloadGroupEntity();
                                                                        entity.setEmpCode(empCode);
                                                                        entity.setEmpName(userInfoTable.getUserName());
                                                                        setjoinPeopleList(entity);
                                                                    }else{
                                                                        empCode = empCode.split("@")[0];
                                                                        addEmpCode(empCode);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        needJoinPeople = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (needJoinPeople) {
                                    //装卸人为空，或者装车任务空时，则获取登录人所在的组员
                                    String teamCode = getUserTeamCode(groupEntityList);
                                    setJoinPeopleListByTeamCode(groupEntityList, teamCode);
                                }
                                //无装卸人时，添加登录人为装卸人
                                addLoginPeople();

                                loadGroupUIAdapter();
                                return;
                            }

                            if (groupEntityList == null) {
                                //获取登录人信息
                                UserInfoTable userInfoTable = userInfoDao.getDataByWorkNum(sharedPreferUtil.getWorkNum());
                                LoadUnloadGroupEntity entity = new LoadUnloadGroupEntity();
                                entity.setEmpCode(userInfoTable.getUserCode());
                                entity.setEmpName(userInfoTable.getUserName());
                                setjoinPeopleList(entity);
                                return;
                            }

                            if (!hasTempData) {
                                //获取当前登录人所在的组
                                String teamCode = getUserTeamCode(groupEntityList);
                                //当没有暂存数据时，添加查询的数据
                                setJoinPeopleListByTeamCode(groupEntityList, teamCode);
                                //无装卸人时，添加登录人为装卸人
                                addLoginPeople();
                                loadGroupUIAdapter();
                            }
                        }
                    }
                });
    }

    /**
     * 无装卸人时，添加登录人为装卸人
     */
    private void addLoginPeople() {
        if (joinPeopleEntityList.isEmpty()) {
            et_joinWorkNum.setText(sharedPreferUtil.getWorkNum());
            addEnjoyPersonMethod();
        }
    }

    /**
     * 添加参与人
     * @param empCode 参与人工号
     */
    private void addEmpCode(String empCode) {
        et_joinWorkNum.setText(empCode);
        addEnjoyPersonMethod();
    }

    /**
     * 获取当前登录人所在的组
     */
    private String getUserTeamCode(List<LoadUnloadGroupEntity> groupEntityList) {
        String teamCode = "";
        if (groupEntityList != null) {
            for (LoadUnloadGroupEntity entity : groupEntityList) {
                if (entity.getEmpCode() != null) {
                    if (entity.getEmpCode().equals(sharedPreferUtil.getValue(Common.USER_CODE))) {
                        tv_loadUnloadGroup.setText(entity.getTeamName());
                        teamCode = entity.getTeamCode();
                        break;
                    }
                }
            }
        }
        return teamCode;
    }

    /**
     * 获取所在组的组员设置为参与人
     */
    private void setJoinPeopleListByTeamCode(List<LoadUnloadGroupEntity> groupEntityList, String teamCode) {
        if (groupEntityList != null) {
            for (LoadUnloadGroupEntity entity : groupEntityList) {
                if (entity.getEmpCode() == null) {
                    continue;
                }
                //获取相同组人员信息
                if (entity.getTeamCode().equals(teamCode)) {
                    setjoinPeopleList(entity);
                }
            }
        }
    }

    /**
     * 设置参与人信息
     */
    private void setjoinPeopleList(LoadUnloadGroupEntity entity) {
        JoinPeopleEntity joinPeopleEntity = new JoinPeopleEntity();
        if (entity.getEmpName() == null) {
            joinPeopleEntity.setUserName("");
        } else {
            joinPeopleEntity.setUserName(entity.getEmpName());
        }
        joinPeopleEntity.setUserCode(entity.getEmpCode());
        joinPeopleEntity.setWorkNum(entity.getEmpCode().split("@")[0]);
        joinPeopleEntity.setUserType(entity.getUserType());
        boolean isExit = false;
        for (JoinPeopleEntity peopleEntity : joinPeopleEntityList) {
            if (peopleEntity.getWorkNum().equals(joinPeopleEntity.getWorkNum())) {
                isExit = true;
                break;
            }
        }
        if (!isExit) {
            joinPeopleEntityList.add(joinPeopleEntity);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (parent.getId()) {
            case R.id.sp_platformNum:
                //月台号
                if (!isSpinnerFirst) {
                    if (position == 0) {
                        actvPlatformNum.setText("");
                    } else {
                        actvPlatformNum.setText(platformList.get(position), false);
                    }
                }
                break;
            default:
                break;
        }
        isSpinnerFirst = false;
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        //解决spinner的item点击事件只能点击一次
        try {
            Class<?> clazz = AdapterView.class;
            Field field = clazz.getDeclaredField("mOldSelectedPosition");
            field.setAccessible(true);
            field.setInt(sp_platformNum, AdapterView.INVALID_POSITION);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    private void notifyDataSetChanged() {
        setListViewHeight(lv_joinPeople);
        adapter.notifyDataSetChanged();
        et_joinWorkNum.setText("");
        et_joinName.setText("");
    }

    /**
     * 为listview动态设置高度（有多少条目就显示多少条目）
     */
    public void setListViewHeight(ListView listView) {
        //获取listView的adapter
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }
        int totalHeight = 0;
        //listAdapter.getCount()返回数据项的数目
        for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        // listView.getDividerHeight()获取子项间分隔符占用的高度
        // params.height最后得到整个ListView完整显示需要的高度
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

    /**
     * 获取发车计划下一站
     */
    private void getCarPlanTaskNextDept(boolean isClick) {
        if (mCheckNextList == null) {
            mCheckNextList = new ArrayList<>();
        }
        mCheckNextList.clear();
        if (mCarPlaneTasks != null) {
            List<CheckBoxItemEntity> nextDeptList = LoadUtil.getCarPlanTaskNextDept(mCarPlaneTasks);
            mCheckNextList.addAll(nextDeptList);
        }
        if (!isClick) {
            if (mCheckNextList != null && !mCheckNextList.isEmpty()) {
                mSelectNextDepts.clear();
                String nextDepts = "";
                for (CheckBoxItemEntity item : mCheckNextList) {
                    if (item.isCheck()) {
                        nextDepts += item.getName() + "/";
                        mSelectNextDepts.add(item);
                    }
                }
                if (!"".equals(nextDepts)) {
                    tvNextDeptName.setText(nextDepts.substring(0, nextDepts.length() - 1));
                } else {
                    tvNextDeptName.setText(mCheckNextList.get(0).getName());
                    mCheckNextList.get(0).setCheck(true);
                    mCheckNextList.get(0).setTempCheck(true);
                    mCheckNextList.get(0).setBeTask(mCheckNextList.get(0).getBeTask());
                    mSelectNextDepts.add(mCheckNextList.get(0));
                }
            }
        } else {
            if (mCheckNextList == null || mCheckNextList.isEmpty()) {
                showToast("未查询到下一站！");
                return;
            }
            //显示下一站对话框
            showNextDeptDialog();
        }
    }

    /**
     * 显示下一站对话框
     */
    private void showNextDeptDialog() {
        DialogUtil.Companion.checkBoxDialog(this, "选择下一站", "确定", "返回", mCheckNextList, new OnClickCallBack() {
            @Override
            public void onCancle() {
            }

            @Override
            public void onSure(Object obj, Object obj1) {
                mSelectNextDepts = (List<CheckBoxItemEntity>) obj;
                if (mSelectNextDepts != null && !mSelectNextDepts.isEmpty()) {
                    String nextDepts = "";
                    for (CheckBoxItemEntity item : mSelectNextDepts) {
                        nextDepts += item.getName() + "/";
                    }
                    tvNextDeptName.setText(nextDepts.substring(0, nextDepts.length() - 1));
                } else {
                    tvNextDeptName.setText("");
                }
            }
        });
    }

    @Override
    public void onItemClickListener(int position) {
        LoadBillTaskEntity entity = mLoadTaskList.get(position);
        entity.setCheck(!entity.isCheck());
        loadUIStowageAdapter();
    }

    @Override
    public void onItemLongClickListener(int position) {

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.cb_check_all:
                if (mLoadTaskList != null) {
                    for (LoadBillTaskEntity item : mLoadTaskList) {
                        item.setCheck(isChecked);
                    }
                    loadUIStowageAdapter();
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        DialogUtil.Companion.setCheckBoxAdapter(null);
    }

    private void loadUIStowageAdapter() {
        if (mStowageNoAdapter == null) {
            if (loadType != -1) {
                mStowageNoAdapter = new SelectStowageNoAdapter(loadType, this, mLoadTaskList, this);
            } else {
                mStowageNoAdapter = new SelectStowageNoAdapter(scanType, this, mLoadTaskList, this);
            }

            rvStowageNo.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
            rvStowageNo.setAdapter(mStowageNoAdapter);
        } else {
            mStowageNoAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public boolean showBack() {
        return false;
    }

    @Override
    public void setBack() {

    }

    @NotNull
    @Override
    public String setTitle() {
        return "装卸信息";
    }

}
